import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
import './css/font-awesome.css'
import VueRouter from 'vue-router'
import VueResource from 'vue-resource'
import RouteMap from './route_map'
import Apps from './App'
import model from './view/utils/Data'

Vue.use(ElementUI)
Vue.use(VueRouter)
Vue.use(VueResource)

let routes = RouteMap.route_map;
model;
const router = new VueRouter({
  routes // （缩写）相当于 routes: routes
});

router.beforeEach((to, from, next) => {
  const userInfo = window.sessionStorage.getItem("userInfo");
  if (to.path !== '/login') {
    if (userInfo == null || userInfo.length === 0) {
      next('/login')
    } else {
      next();
    }
  } else {
    next();
  }
})

const app = new Vue({
  router: router,
  render: h => h(Apps)
}).$mount('#app');
